package com.service.business.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.service.business.base.controller.rep.BannerRep;
import com.service.business.base.service.BannerService;
import com.service.dao.enums.BannerEnum;
import com.service.dao.enums.CommonStatusEnums;
import com.service.dao.mapper.BannerMapper;
import com.service.dao.model.Banner;
import com.service.business.support.Language;
import com.service.utility.modelmapper.ModelMapperUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <dl>
 * <dt>platform</dt>
 * <dd>Description:</dd>
 * <dd>Copyright: Copyright (C) 2015</dd>
 * <dd>Company: </dd>
 * <dd>CreateDate: 2019年05月13日</dd>
 * </dl>
 *
 * @author
 */
@Slf4j
@Service
public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner> implements BannerService {

    @Override
    public List<BannerRep> listBannerByBizType(BannerEnum.BizType bizType) {
        return list(new QueryWrapper<Banner>().lambda()
                .eq(Banner::getLanguage, Language.LANG.get())
                .eq(Banner::getBizType, bizType.getCode())
                .eq(Banner::getBannerStatus, CommonStatusEnums.ACTIVE.getCode())).stream()
                .filter(item -> StringUtils.isNotBlank(item.getPicture())).map(item -> ModelMapperUtil.map(item, BannerRep.class))
                .collect(Collectors.toList());
    }

}
